package design.mode.effective_java.chapter9.item61;

/**
 * @author ZhongMingde on 2021/9/1
 */

public class Test2 {

    public void test1() {
        Long sum = 0L;
        for (int i = 0; i < Integer.MAX_VALUE; i++) {
            sum += i;
        }
        System.out.println("test1" + sum);
    }

    public void test2() {
        long sum = 0L;
        for (int i = 0; i < Integer.MAX_VALUE; i++) {
            sum += i;
        }
        System.out.println("test2" + sum);
    }

    public static void main(String[] args) {
        Test2 test2 = new Test2();
        long start = System.nanoTime();
        test2.test1();
        long end = System.nanoTime();
        System.out.println((double) (end - start) / 1_000_000_000);
        start = System.nanoTime();
        test2.test2();
        end = System.nanoTime();
        System.out.println((double) (end - start) / 1_000_000_000);
    }
}
